<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.SQLException" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page language="java" import="java.lang.*" %>
<%@ page import = "java.sql.SQLException" %>
<%@ page import = "com.seniorproject.aims.*" %>
<%@ page import = "java.util.List" %>
<%@page import="java.util.ArrayList"%>
<%@ page import = "java.util.Properties" %>
<%@ page import = "javax.servlet.ServletContext" %>
<%@ page import = "java.io.File" %>
<%@ page import = "java.io.InputStream" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>Employee Edit Personal Info</title>
	
	<link rel="stylesheet" type="text/css" href="css/stylev2.css" /> 
	<link rel="stylesheet" type="text/css" href="css/frame2.css" />
	
	<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
	<script type="text/javascript" src="js/jquery-2.1.1.min.js"></script>
	<script src="js/jquery.ajaxfileupload.js"></script>
	
	<style type="text/css">
		a {
	      text-decoration:none;
	   }
	</style>
	
	<script type="text/javascript">
		$(document).ready(function() {
				var patt = new RegExp("[#$%^*?!~`<>]");
				var src_path_full = "null";
				
				$('input[type="file"]').ajaxfileupload({
					'action' : 'UploadServletStudentAddNormal',
					'onComplete' : function(response) {
						$('#upload').hide();
						$('#message').show();
						
						var statusVal = JSON.stringify(response.status);
			
						if(statusVal == "false")
						{
							$("#message").html("<font color='red'>"+ JSON.stringify(response.message) +" </font>");
							
						}	
						if(statusVal == "true")
						{

							 var xmlhttp;
								
								if(window.XMLHttpRequest) {
									// code for IE7+, Firefox, Chrome, Opera, Safari
									xmlhttp = new XMLHttpRequest();
								}
								else {
									// code for IE6, IE5
									xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
								}
								
								xmlhttp.onreadystatechange = function() {
									if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {	
										
										//alert("Back from student_edit_personal_get_photo_temp:");
										
							
									
									
											
									src_path_full = xmlhttp.responseText;
									//alert("src_path_full:"+src_path_full);
									var src_path_temp = src_path_full.split("/");
									var length = src_path_temp.length;
									
									var src_path_a = src_path_temp[length-2];
									var src_path_b = src_path_temp[length-1];
									
									var src_path = src_path_a+"/"+src_path_b;
								
									
									
									
									$("#student_image").attr('src',src_path);
									$("#message").html("<font color='green'>"+ JSON.stringify(response.message) +" </font>");		
											
									// end if check state
									}// end function
								
								}						
								xmlhttp.open("POST", "student_edit_personal_get_photo_temp.jsp", true);
								xmlhttp.send();
				
						}			
					},
					'onStart' : function() {
						$('#upload').show();
						$('#message').hide();
					}
				});
		
				$('#save').click(function(){
					
					//alert("Save Active");///////////////////
					 var index = "<%=request.getParameter("index")%>";
					 var check = "";
					 var error = "กรุณากรอก";
					 //////////////////////////////////////////////////////////////
				     var title = document.getElementsByName('title');
					 var title_value;
					 
					 for(var i = 0; i < title.length; i++){
					    if(title[i].checked){
					        title_value = title[i].value;
					    }
					 }
				    
					if(title_value==null)
					{
						error = error + " คำนำหน้า";
						check="X";
					
					}
					else if (title_value=="etc")
					{
						title_value =  $('#title_etc').val();
						//alert(title_value);/////////////try//////////////////////////////////
							if(title_value==null){
								
									error = error + " คำนำหน้าแบบกำหนดเอง";
									check="X";
								
							} 
							
					}
					//////////////////////////////////////////////////////////////
					var name_th = document.getElementById('name');
					var name_th_value = name_th.value;
					if(name_th_value=="")
					{
						error = error + " ชื่อภาษาไทย";	
						check="X";
					}
					if(patt.test(name_th_value)) { 
						
						check="X";
						error = error +"กรุณาหลีกเลี่ยงอักขะพิเศษ";
					}
					//////////////////////////////////////////////////////////////
					var status = document.getElementById('status');
					var status_value = status.value;
					if(status_value=="")
					{
						error = error + " สถานะ";	
						check="X";
					}
					//////////////////////////////////////////////////////////////
					 
					var surname_th = document.getElementById('surname');
					var surname_th_value = surname_th.value;
					if(surname_th_value=="")
					{
						error = error + " นามสกุลภาษาไทย";	
						check="X";
					}
					if(patt.test(surname_th_value)) { 
						
						check="X";
						error = error +"กรุณาหลีกเลี่ยงอักขะพิเศษ";
					}
					
					 //////////////////////////////////////////////////////////////
					var gender = document.getElementsByName('gender');
					var gender_value;
					
					 for(var j = 0; j < gender.length; j++){
						    if(gender[j].checked){
						        gender_value = gender[j].value;
						    }
						 }
				
					 if(gender_value==null)
					 {
						 error = error + " เพศ";
						 check="X";
					 }
					
					//////////////////////////////////////////////////////////////
					
					 var date_of_birth = document.getElementById('date_of_birth');
					 var date_of_birth_value = date_of_birth.value; 
					 
					 if(date_of_birth_value=="")
					 {
						 error = error + " วันเกิด";
						 check="X";
					 }
					 //////////////////////////////////////////////////////////////
				 	 var select_department = document.getElementById('department');
					 var department_value = select_department.options[select_department.selectedIndex].value;
					 if(department_value=="select")
					{
						 error = error + "ภาควิชา";
						 check = "X";
					}
					//////////////////////////////////////////////
					////////finally Check ///////////
					if(!error=="กรุณากรอก"){
							alert(""+error+"");
					}
					else{
					//	alert(":"+error+":");
					}
					////////////////// get data///////////////////
					
					var personal_id = document.getElementById('personalId');
		 			var	 personal_id_value = personal_id.value;
		 			if(patt.test(personal_id_value)) { 
						
						check="X";
						error = error +"กรุณาหลีกเลี่ยงอักขะพิเศษ";
					}
		 				 
					var name_en = document.getElementById('name_en');
					var name_en_value = name_en.value;
					if(patt.test(name_en_value)) { 
						
						check="X";
						error = error +"กรุณาหลีกเลี่ยงอักขะพิเศษ";
					}
					var surname_en = document.getElementById('surname_en');
					var surname_en_value = surname_en.value;
					
					if(patt.test(surname_en_value)) { 
						
						check="X";
						error = error +"กรุณาหลีกเลี่ยงอักขะพิเศษ";
					}
					
					
				     var marital_status = document.getElementsByName('marital_status');
					 var marital_status_value = null;
					 					 
					 for(var i = 0; i < marital_status.length; i++){
					    if(marital_status[i].checked){
					        marital_status_value = marital_status[i].value;
					    }
					 }
					 
					 
					var address = document.getElementById('address');
					var address_value = address.value;
					if(patt.test(address_value)) { 
						
						check="X";
						error = error +"กรุณาหลีกเลี่ยงอักขะพิเศษ";
					}
				
					
					var tel = document.getElementById('phonenumber');
					var tel_value = tel.value;
					
					if(patt.test(tel_value)) { 
						
						check="X";
						error = error +"กรุณาหลีกเลี่ยงอักขะพิเศษ";
					}
					var patt_email = new RegExp("[#$%^*?!~`<>]");
					var email = document.getElementById('email');
					var email_value = email.value;
					if(patt_email.test(email_value)) { 
						
						check="X";
						error = error +"กรุณาหลีกเลี่ยงอักขะพิเศษ";
					}
					
					
					var facebook = document.getElementById('facebook');
					var facebook_value = facebook.value;
					
					if(patt.test(facebook_value)) { 
						
						check="X";
						error = error +"กรุณาหลีกเลี่ยงอักขะพิเศษ";
					}
					
					var picture_value = src_path_full;
					
					 var pos = document.getElementById('position');		
					 var pos_value = pos.value;
					 
					//////////////////END GET DATA //////////////////
						//alert("check:"+check);
					if(check=="")
					{
						/* AJAX */
						var xmlhttp;
						
						if(window.XMLHttpRequest) {
							// code for IE7+, Firefox, Chrome, Opera, Safari
							xmlhttp = new XMLHttpRequest();
						}
						else {
							// code for IE6, IE5
							xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
						}
						
						xmlhttp.onreadystatechange = function() {
							if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {									
							
								//alert("I'm back");
								var result = xmlhttp.responseText;
								//alert("result:"+result);
								if(result=="fail"){
									alert("บันทึกข้อมูลไม่สำเร็จกรุณาตรวจสอบข้อมูล");
									
								}
								else if(result=="success"){
									alert("บันทึกข้อมูลสำเร็จ");
									window.location="/AIMS_Project/admin_employee.jsp";
									// redirect
									
								}else{
									alert("บันทึกข้อมูลไม่สำเร็จ");
									
								}
								
								//document.location.href = "admin_account.jsp";
							}
						}
						
						var parameter = "personal_id="+personal_id_value+
										"&title_th="+title_value+
									    "&name_th="+name_th_value+
									    "&surname_th="+surname_th_value+
									    "&name_en="+name_en_value+
										"&surname_en="+surname_en_value+
										"&gender="+gender_value+
										"&marital_status="+marital_status_value+
										"&date_of_birth="+date_of_birth_value+
										"&address="+address_value+
										"&tel="+tel_value+
										"&email="+email_value+
										"&facebook="+facebook_value+
										"&picture="+picture_value+
										"&department_id="+department_value+
										"&position="+pos_value+
										"&index="+index+
										"&status="+status_value;
						
						//alert(parameter);
						xmlhttp.open("POST", "admin_employee_edit_personal_save.jsp?"+parameter, true);
						xmlhttp.send();
					}else{
						
						alert("กรุณาตรวจสอบความถูกต้องอีกครั้ง");
						
					}
				
				});
				
			});
		
		
		// check title etc was click
		function click_title_etc() {
			document.getElementById('title_etc').readOnly = false;
			$('#title_etc').focus();
		}
		
		function click_title() {
			document.getElementById('title_etc').readOnly = true;
		}
		
	
	</script>
</head>
<body>
<%
	// get session
	String strUser = String.valueOf(session.getAttribute("sUser"));
	HttpSession htp_session = request.getSession();
	
	// check session
		if (htp_session == null || htp_session.getAttribute("sUser") == null) {
		    // Forward the control to login.jsp if authentication fails or session expires
		    request.getRequestDispatcher("/login.jsp").forward(request,
		        response);
		}
		if(!"admin".equals(htp_session.getAttribute("sUser"))){%>
			<script>alert("This user dont have PERMISSION to access this zone.");</script>
			<meta HTTP-EQUIV="Refresh" CONTENT="0; URL=system_select.jsp"> 	
	<%}
	
	
	//set Database Connection
	String hostProps = "";
	String usernameProps  = "";
	String passwordProps  = "";
	String databaseProps = "";
	
	try {
		//get current path
		ServletContext servletContext = request.getSession().getServletContext();
		
		InputStream input = servletContext.getResourceAsStream("/properties/connectDB.properties");
		Properties props = new Properties();
		
		props.load(input);

		hostProps  = props.getProperty("host");
		usernameProps  = props.getProperty("username");
		passwordProps  = props.getProperty("password");
		databaseProps = props.getProperty("database");
	} catch (Exception e) { 
		out.println(e);  
	}
	
	// connect database
	Connection connect = null;		
	try {
		Class.forName("com.mysql.jdbc.Driver");
	
		connect =  DriverManager.getConnection("jdbc:mysql://" + hostProps  + "/" + databaseProps +
				"?user=" + usernameProps  + "&password=" + passwordProps );
	
		if(connect != null){
			System.out.println("Database Connect Sucesses.");
		} else {
			System.out.println("Database Connect Failed.");	
		}

	} catch (Exception e) {
		out.println(e.getMessage());
		e.printStackTrace();
	}
	
	/* find department in database */
	List<Department> department = new ArrayList<Department>();
	int departmentIdOld =0;
	String departmentNameOld="";
	
	try {			   
		ResultSet rs = connect.createStatement().executeQuery("SELECT department_id, department_name_th, department_name_en, department_name_short " 
				+ " FROM department " + " ORDER BY department_name_en");
		
		while(rs.next()) {
			Department depart = new Department();
			
			depart.setDepartmentId(Integer.parseInt(rs.getString("department_id")));
			depart.setDepartmentNameTH(rs.getString("department_name_th"));
			depart.setDepartmentNameEN(rs.getString("department_name_en"));
			depart.setDepartmentNameShort(rs.getString("department_name_short"));
			
			department.add(depart);
		}
		
	} catch (SQLException e) {
		e.printStackTrace();
	}
	
	String index = request.getParameter("index");
	
	System.out.println("employee_index  "+index);//////try//////
	
	if(index==null)
	{
		 response.sendRedirect("admin_employee.jsp");
	}
	
	System.out.println("@ employee_edit_personal index:"+index);
	
	Employee emp = new Employee();
	
	String title_th = "";
	String title_en = "";
	
	
	String sql_cmd =" SELECT E.position,  E.picture ,E.status ,E.department_id, N.title_th, N.title_en, "+
			" N.name_th, N.surname_th , N.name_en , N.surname_en ,P.personal_id, P.gender,P.marital_status ,"+
			" P.address , P.phone_number, P.email , P.facebook ,P.date_of_birth ,"+
			" D.department_name_th"+
			" FROM employee E , full_name N , department D ,people P "+
			" WHERE E.index = P.index AND P.full_name_id = N.full_name_id " +
			" AND E.department_id = D.department_id "+
			" AND E.index = '"+index+"'";
	
	System.out.println("sql_cmd:"+sql_cmd);
	
	ResultSet rs = connect.createStatement().executeQuery(sql_cmd);
	
	while(rs.next())
	{
		System.out.println("Found Result");		
		departmentIdOld = Integer.parseInt(rs.getString("department_id"));
		departmentNameOld = rs.getString("department_name_th");
				
		String src_path_full = rs.getString("picture");
		System.out.println("src_path_full:"+src_path_full);
	//	System.out.println(src_path_full.equals("null"));
	//	System.out.println(!("null").equals(src_path_full));
	//	System.out.print((src_path_full!=null)||(!("null").equals(src_path_full)));
		
		if((src_path_full!=null)&&(!("null").equals(src_path_full)))
		{
			String[] src_path_temp = src_path_full.split("/");	
			int length = src_path_temp.length;
			
			String src_path_a = src_path_temp[length-2];
			String src_path_b = src_path_temp[length-1];
			
			String src_path = src_path_a+"/"+src_path_b;
			
			emp.setPicture(src_path);
		
		}else{
			emp.setPicture("upload/default_person_icon.jpg");
			
		}
		
		
		if(rs.getString("personal_id")==null || "null".equals(rs.getString("personal_id")))
		{
			emp.setPersonalId("");
		}	
		else{
			emp.setPersonalId(rs.getString("personal_id"));
		}
		
		
		
		System.out.println("title_th:"+rs.getString("title_th"));////////////////////
		if(rs.getString("title_th")==null || "null".equals(rs.getString("title_th")))
		{
			emp.setTitleTH("");	
		}else{
			emp.setTitleTH(rs.getString("title_th"));
		}
		
		if(rs.getString("title_en")==null || "null".equals(rs.getString("title_en")))
		{
			emp.setTitleEN("");	
		}else{
			emp.setTitleEN(rs.getString("title_en"));
		}
		
		
		emp.setNameTH(rs.getString("name_th"));
		emp.setSurnameTH(rs.getString("surname_th"));
		
		
		if(rs.getString("name_en")==null || "null".equals(rs.getString("name_en")))
		{
			emp.setNameEN("");
		}else{
			emp.setNameEN(rs.getString("name_en"));
		}
		
	
		if(rs.getString("surname_en")==null || "null".equals(rs.getString("surname_en")))
		{
			emp.setSurnameEN("");
		}else{
			emp.setSurnameEN(rs.getString("surname_en"));
		}
		
		if(rs.getString("date_of_birth")==null || "null".equals(rs.getString("date_of_birth")))
		{
			emp.setBirtgdate("");
		}else{
			emp.setBirtgdate(rs.getString("date_of_birth"));				
		}
	
					
		if(rs.getString("gender").equals("M"))
		{
			emp.setGender("ชาย");
		}else
		{
			emp.setGender("หญิง");
		}
		
		System.out.println("marital_status:"+rs.getString("marital_status"));
		if(rs.getString("marital_status")==null || "null".equals(rs.getString("marital_status")))
		{
			emp.setMaritalStatus("");
			
		}else{
			System.out.println("rs marital_status : "+rs.getString("marital_status"));/////////////////
			
			emp.setMaritalStatus(rs.getString("marital_status"));
		}
			
		
		if(rs.getString("address")==null || "null".equals(rs.getString("address")))
		{
			emp.setAddress("");
		}else{
			emp.setAddress(rs.getString("address"));
		}
		if(rs.getString("phone_number")==null || "null".equals(rs.getString("phone_number")))
		{
			emp.setTelephone("");
		}else{
			emp.setTelephone(rs.getString("phone_number"));
		}
		if(rs.getString("email")==null || "null".equals(rs.getString("email")))
		{
			emp.setEmail("");
		}else{
			emp.setEmail(rs.getString("email"));
		}
		if(rs.getString("status")==null || "null".equals(rs.getString("status")))
		{
			emp.setStatus("");
		}else{
			emp.setStatus(rs.getString("status"));
		}
		if(rs.getString("facebook")==null || "null".equals(rs.getString("facebook")))
		{
			emp.setFacebook("");
		}else{
			emp.setFacebook(rs.getString("facebook"));
		}
		
		emp.setDepartment(rs.getString("department_name_th"));
	
		title_th = rs.getString("title_th");	
		title_en = rs.getString("title_en");	
		
		emp.setPosition(rs.getString("position"));
		
		
	}
	
	connect.close();
	
	System.out.println("End Jsp");
				
%>

	<div id="page-wrap">
		<div id="inside">
			<table border="0">
				<tr style="font-size:24px">
					<td width="600" height="100" style= "background-color: #273b80;border: 0px ;padding: 0px; 0px;" >
						<div id="header_banner-2"></div>
					</td>
					
					<td width="680" height="100" style= "background-color: #273b80;border: 0px;padding: 0px; 0px;" >
						<p align="right"><label><font size="4" color="#ffffff">username : <%=strUser%>&nbsp;&nbsp;</font></label></p>
						<a href="logout.jsp"><p align="right"><label style="cursor: pointer;"><font size="3" color="#ffffff">log out &nbsp;</font></label></p></a>
					</td>
				</tr>
			</table>
				
				<div id="main-content-ac">
						
						<div class="imageFrame">บุคลากร / แก้ไขข้อมูลส่วนตัว</div>
						
						<br/><br/><br/><br/><br/>
						<center>
								<table width="1200px" >								 
									  <tr style="font-size:20px">
										  		<td  width="50" height="50" rowspan="6" style="text-align: center;">
									        			
									        			<img id="student_image" src="<%=emp.getPicture() %>" style="width:130px;height:160px;	">
									       
									         			 <form>	
																<input type="file" name="file"/><br />
																<div id="upload" style="display: none;">Uploading..</div>
																<div id="message">
																</div>
														  </form>
									      
									      	  </td>
						        
						        	  </tr>
									  
								
									  <tr style="font-size:24px">
				        	
								                <td width="400" height="50">
								                	<font size="5"><strong>เลขประจำตัวประชาชน</strong></font>
								                </td>
								                <td width="600" height="50">
								                	<input type="text" id="personalId" name="personalId" style="font-size:18px" value="<%=emp.getPersonalId() %>"/>
								         		
								                </td>
				                	      
				         			 </tr>
								 
									 <tr style="font-size:24px">
											<input type="hidden" name="title_old" value="<%=emp.getTitleEN()%>">
								                <td height="50">
								                	<font size="5"><strong>คำนำหน้า</strong></font>
								                      <label><font size="5" color="#FF0000">*</font></label>
								                </td>
								                <td height="50">
								   <%
								   				if("Mr.".equals(emp.getTitleEN()) || "นาย".equals(title_th)) {
								   					System.out.println("MR");////////////////////////////try////////////////////////
								   %>             	
								                      <label>
								                        <input type="radio" name="title" id="title" value="นาย" id="mr" checked="checked" onclick="click_title()" />
								                        <font size="5">นาย</font>
								                      </label>
								                      &nbsp;&nbsp;
								                      <label>
								                        <input type="radio" name="title" id="title" value="นาง" id="mrs" onclick="click_title()" />
								                        <font size="5">นาง</font>
								                      </label>
								                      &nbsp;&nbsp;
								                      <label>
								                        <input type="radio" name="title" id="title" value="นางสาว" id="miss" onclick="click_title()" />
								                        <font size="5">นางสาว</font>
								                      </label>
								                      &nbsp;&nbsp;
								                      <label>
								                        <input type="radio" name="title" id="title" value="etc" id="etc" onclick="click_title_etc()" />
								                        <font size="5">อื่นๆ</font>
								                       
								                        <input type="text"  style="font-size:18px" size="10" id="title_etc" name="title_etc" readonly="readonly"/>
								                      </label>
									<%
								   				}
								   				else if("Mrs.".equals(emp.getTitleEN()) || "นาง".equals(title_th)) {
								   					System.out.println("MRS");////////////////////////////try////////////////////////
									%>
												 	  <label>
								                        <input type="radio" name="title" id="title" value="นาย" id="mr" onclick="click_title()" />
								                        <font size="5">นาย</font>
								                      </label>
								                      &nbsp;&nbsp;
								                      <label>
								                        <input type="radio" name="title" id="title" value="นาง" id="mrs" checked="checked" onclick="click_title()" />
								                        <font size="5">นาง</font>
								                      </label>
								                      &nbsp;&nbsp;
								                      <label>
								                        <input type="radio" name="title" id="title" value="นางสาว" id="miss" onclick="click_title()" />
								                        <font size="5">นางสาว</font>
								                      </label>
								                      &nbsp;&nbsp;
								                      <label>
								                        <input type="radio" name="title" id="title" value="etc" id="etc" onclick="click_title_etc()" />
								                        <font size="5">อื่นๆ</font>
								                        
								                        <input type="text"  style="font-size:18px" size="10" id="title_etc" name="title_etc" readonly="readonly"/>
								                      </label>
								    <%
								   				}
								   				else if("Miss".equals(emp.getTitleEN()) || "นางสาว".equals(title_th)) {
								   					System.out.println("MISS");////////////////////////////try////////////////////////
								    %>
												 	  <label>
								                        <input type="radio" name="title" id="title" value="นาย" id="mr" onclick="click_title()" />
								                        <font size="5">นาย</font>
								                      </label>
								                      &nbsp;&nbsp;
								                      <label>
								                        <input type="radio" name="title" id="title" value="นาง" id="mrs" onclick="click_title()" />
								                        <font size="5">นาง</font>
								                      </label>
								                      &nbsp;&nbsp;
								                      <label>
								                        <input type="radio" name="title" id="title" value="นางสาว" id="miss" checked="checked" onclick="click_title()" />
								                        <font size="5">นางสาว</font>
								                      </label>
								                      &nbsp;&nbsp;
								                      <label>
								                        <input type="radio" name="title" id="title" value="etc" id="etc" onclick="click_title_etc()" />
								                        <font size="5">อื่นๆ</font>
								                       
								                        <input type="text"  style="font-size:18px" size="10" id="title_etc" name="title_etc" readonly="readonly"/>
								                      </label>
								    <%
								   				}
								   				else {
								   					System.out.println("NO");////////////////////////////try////////////////////////
								    %>	
												 	  <label>
								                        <input type="radio" name="title" id="title" value="นาย" id="mr" onclick="click_title()" />
								                        <font size="5">นาย</font>
								                      </label>
								                      &nbsp;&nbsp;
								                      <label>
								                        <input type="radio" name="title" id="title" value="นาง" id="mrs" onclick="click_title()" />
								                        <font size="5">นาง</font>
								                      </label>
								                      &nbsp;&nbsp;
								                      <label>
								                        <input type="radio" name="title" id="title" value="นางสาว" id="miss" onclick="click_title()"  />
								                        <font size="5">นางสาว</font>
								                      </label>
								                      &nbsp;&nbsp;
								                      <label>
								                        <input type="radio" name="title" id="title" value="etc" id="etc" checked="checked" onclick="click_title_etc()" />
								                        <font size="5">อื่นๆ</font>
								                        
								                        <input type="text"  style="font-size:18px" size="10" id="title_etc" name="title_etc" value="<%=emp.getTitleTH()%>" />
								                      </label>
								    <%
								   				}
								    %>	                      
								                </td>
								      </tr>
									  
									  <tr style="font-size:24px">
								            <input type="hidden" name="name_old" value="<%=emp.getNameTH()%>">
								                <td height="50">
								                	<font size="5"><strong>ชื่อ</strong></font>
								                      <label><font size="5" color="#FF0000">*</font></label>
								                </td>
								                <td height="50">
								                	<input name="name" id="name" type="text" style="font-size:18px" value="<%=emp.getNameTH() %>"/>
								        	        </td>
				         			   </tr>
									  
									   <tr style="font-size:24px">
							        		    <input type="hidden" name="surname_old" value="<%=emp.getSurnameTH()%>">
							                <td height="50">
							                	<font size="5"><strong>นามสกุล</strong></font>
								                      <label><font size="5" color="#FF0000">*</font></label>
							                </td>
							                <td height="50">
							                	<input name="surname" id="surname" type="text" style="font-size:18px" value="<%=emp.getSurnameTH() %>" />
							                </td>
					                
				          			  </tr>
				            
									  
									
									  
									  <tr style="font-size:24px">
							            <input type="hidden" name="name_en_old" value="<%=emp.getNameEN()%>">
							                <td height="50">
							                	<font size="5"><strong>ชื่อ(ภาษาอังกฤษ)</strong></font>
								                      <label><font size="5" color="#FF0000">*</font></label>
							                </td>
							                <td height="50">
							                	<input name="name_en" id="name_en" type="text" style="font-size:18px" value="<%=emp.getNameEN() %>" />
							                </td>
				       			     </tr>
									  
									   <tr style="font-size:24px">
								            <input type="hidden" name="surname_en_old" value="<%=emp.getSurnameEN()%>">				            
								             	<td  width="400" height="50"></td>
								                <td height="50">
								                	<font size="5"><strong>นามสกุล(ภาษาอังกฤษ)</strong></font>
								                      <label><font size="5" color="#FF0000">*</font></label>
								                </td>
								                <td height="50">
								                	<input name="surname_en" id="surname_en" type="text" style="font-size:18px" value="<%=emp.getSurnameEN() %>" />
								                </td>
				        		     </tr>
									  
									  <tr style="font-size:24px">
								            <input type="hidden" name="gender_old" value="<%=emp.getGender()%>">	
												<td  width="400" height="50"></td>
								                <td height="50">
								                	<font size="5"><strong>เพศ</strong></font>
								                      <label><font size="5" color="#FF0000">*</font></label>
								                </td>
								                <td height="50">
								   
								    <%
								    				if("ชาย".equals(emp.getGender())) {
								    %>
								   					 <label>
								                        <input type="radio" name="gender" value="M" id="man" checked="checked" />
								                        <font size="5">ชาย</font></label>
								                        
								                        &nbsp;&nbsp;
								                      
								                      <label>
								                        <input type="radio" name="gender" value="F" id="women" />
								                        <font size="5">หญิง</font></label>
								    <%
								    				}
								    				else {
								    %>
								    					<input type="radio" name="gender" value="M" id="man" />
								                        <font size="5">ชาย</font></label>
								    		                        
								                        &nbsp;&nbsp;
								                      
								                      <label>
								                        <input type="radio" name="gender" value="F" id="women" checked="checked" />
								                        <font size="5">หญิง</font></label>
								    <%					
								    				}
								    %>
								                      
								                </td>
								       </tr>
									  
									   <tr style="font-size:24px">
								             <input type="hidden" name="marital_status_old" value="<%=emp.getMaritalStatus()%>">	
								             	<td  width="400" height="50"></td>
								                <td height="50">
								                	<font size="5"><strong>สถานภาพ</strong></font>
								                </td>
								                <td height="50">
								   <%	
								   		System.out.println("getMaritalStatus : "+emp.getMaritalStatus());
								   			if("โสด".equals(emp.getMaritalStatus())) {
								   %>
								                      <label>
								                        <input type="radio" name="marital_status" id="marital_status" value="โสด" checked="checked" />
								                        <font size="5">โสด</font></label>
								                      &nbsp;&nbsp;
								                      <label>
								                        <input type="radio" name="marital_status"id="marital_status" value="แต่งงาน" />
								                        <font size="5">แต่งงาน</font></label>
								                          &nbsp;&nbsp;
								                      <label>
								                        <input type="radio" name="marital_status" id="marital_status" value="หย่าร้าง" />
								                        <font size="5">หย่าร้าง</font></label>
								   <%
								   			}
								   			else if("แต่งงาน".equals(emp.getMaritalStatus())) {
								   %>               
								                      <label>
								                        <input type="radio" name="marital_status" id="marital_status" value="โสด" />
								                        <font size="5">โสด</font></label>
								                      &nbsp;&nbsp;
								                      <label>
								                        <input type="radio" name="marital_status"id="marital_status" value="แต่งงาน" checked="checked" />
								                        <font size="5">แต่งงาน</font></label>
								                          &nbsp;&nbsp;
								                      <label>
								                        <input type="radio" name="marital_status" id="marital_status" value="หย่าร้าง" />
								                        <font size="5">หย่าร้าง</font></label>		
								   <%
								   			}
								   			else if("หย่าร้าง".equals(emp.getMaritalStatus())) {
								   %>                    
								   		                      <label>
								                        <input type="radio" name="marital_status" id="marital_status" value="โสด" />
								                        <font size="5">โสด</font></label>
								                      &nbsp;&nbsp;
								                      <label>
								                        <input type="radio" name="marital_status"id="marital_status" value="แต่งงาน" />
								                        <font size="5">แต่งงาน</font></label>
								                          &nbsp;&nbsp;
								                      <label>
								                        <input type="radio" name="marital_status" id="marital_status" value="หย่าร้าง" checked="checked" />
								                        <font size="5">หย่าร้าง</font></label>		
								   <%
								   			}
								   			else {
								   				%>                    
					   		                      <label>
						                        <input type="radio" name="marital_status" id="marital_status" value="โสด" />
						                        <font size="5">โสด</font></label>
						                      &nbsp;&nbsp;
						                      <label>
						                        <input type="radio" name="marital_status"id="marital_status" value="แต่งงาน" />
						                        <font size="5">แต่งงาน</font></label>
						                          &nbsp;&nbsp;
						                      <label>
						                        <input type="radio" name="marital_status" id="marital_status" value="หย่าร้าง" />
						                        <font size="5">หย่าร้าง</font></label>		
								   <%
								   			}
								   %>                               
								           
								                </td>
							           </tr>
									  
									  <tr style="font-size:20px">
									  	<td  width="400" height="50"></td>
										<td height="50" style="font-weight: bold;"><font size="5">วัน/เดือน/ปีเกิด</font></td>
										<td height="50">
												   <input type="date" id="date_of_birth" name="date_of_birth" value="<%=emp.getBirtgdate() %>" style="font-size: 18px;"/>
										</td>           
									  </tr>										  
									  
									  <tr style="font-size:20px">
									  	<td  width="400" height="50"></td>
										<td height="50" style="font-weight: bold;"><font size="5">ที่อยู่</font></td>
										<td height="50">
											<textarea name="address" id="address" cols="50" rows="3" style="font-size: 18px;"> <%=emp.getAddress() %> </textarea>
										</td>           
									  </tr>	
									  
									  <tr style="font-size:20px">
									  	<td  width="400" height="50"></td>
										<td height="50" style="font-weight: bold;"><font size="5">เบอร์โทรศัพท์</font></td>
												
										<td height="50">
												<input name="phonenumber" id="phonenumber" type="text" style="font-size:18px" value="<%=emp.getTelephone()%>" />
										</td>           
									  </tr>
									  
									  <tr style="font-size:20px">
									  	<td  width="400" height="50"></td>
										<td height="50" style="font-weight: bold;"><font size="5">อีเมลล์</font></td>
			
										<td height="50">
											<input name="email" id="email" type="text" style="font-size:18px" value="<%=emp.getEmail() %>" />								
										</td>           
									  </tr>
									  
									  <tr style="font-size:20px">
									  	<td  width="400" height="50"></td>
										<td height="50" style="font-weight: bold;"><font size="5">Facebook</font></td>
											
										<td height="50">
											<input name="facebook" id="facebook" type="text" style="font-size:18px" value="<%=emp.getFacebook() %>" />
										</td>           
									  </tr>
									  	  
									    <tr style="font-size:24px">
									    	<td  width="400" height="50"></td>
						            	<td height="50" width="250">
						                	<font size="5"><strong>ภาควิชา</strong></font>
								                      <label><font size="5" color="#FF0000">*</font></label>
						                </td>
						              	
						              	<input type="hidden" name="departmentId" id="departmentId" value="<%=departmentIdOld %>" />
						              	<input type="hidden" name="departmentName" id="departmentName" value="<%=departmentNameOld %>" />
						              	<td height="50">
						                	<select name="department" id="department" style="font-size: 18px;">
							                	<option value="<%=departmentIdOld %>"><%=departmentNameOld %></option>
<%
												for(Department dept : department) {
													if(departmentIdOld == dept.getDepartmentId()) {
														
													}
													else {
%>
														<option value="<%=dept.getDepartmentId()%>" id="<%=dept.getDepartmentId()%>"><%=dept.getDepartmentNameTH()%></option>	
<%												
													}
												}
%>
							                </select>
							        	</td>
						            </tr>
									  
									  <tr style="font-size:20px">
									  	<td  width="400" height="50"></td>
										<td height="50" style="font-weight: bold;">
											<font size="5">ตำแหน่ง</font>
								                      <label><font size="5" color="#FF0000">*</font></label>
										</td>
											<input type="hidden" name="position_old" id="position_old" value="<%=emp.getPosition() %>" />
										<td height="50">
											<input type="text" name="position" id="position" value="<%=emp.getPosition() %>" style="font-size: 18px;" />
										</td>           
									  </tr>
									  
									  <tr style="font-size:20px">
									  	<td  width="400" height="50"></td>
										<td height="50" style="font-weight: bold;">
											<font size="5">สถานะ</font>
								                      <label><font size="5" color="#FF0000">*</font></label>
								        </td>
										
										<td height="50">
											<select name="status" id="status" style="font-size: 18px;">
													<option value="<%=emp.getStatus()%>"><%=emp.getStatus()%></option>
								<%
												if("ปกติ".equals(emp.getStatus())) { }
												else {
								%>
													<option value="ปกติ">ปกติ</option>
								<%
												}
												if("ลาออก".equals(emp.getStatus())) { }
												else {
								%>
													<option value="ลาออก">ลาออก</option>
								<%
												}
												if("อื่นๆ".equals(emp.getStatus())) { }
												else {
								%>
													<option value="อื่นๆ">อื่นๆ</option>
								<%
												}
								%>
											</select>	
										</td>           
									  </tr>
									  
									  <tr>
											<td>
											</td>
							            	<td colspan="2">
							            		<label><font size="3" color="#FF0000">หมายเหตุ: * คือ ข้อมูลสำคัญ จำเป็นต้องกรอก</font></label>
							            	</td>
						              </tr>
									  
									  <tr style="font-size:20px">
									 	<td  width="400" height="50"></td>
									  	<td height="50">
									  		<input type="button" name="save" id="save"  value="บันทึก" class="buttonStyle"/>
										
									  	</td>
									  	<td height="50">
									  		<a href="admin_employee.jsp"><button class="buttonStyle">cancel</button></a>
										
									  	</td>										          
									  </tr>
								</table>
							
						</center>
						
						<br><br><br>
				
			<div style="clear: both;"></div>
				
			<div id="footer"></div>
			
		</div>		
			<div style="clear: both;"></div>		
   </div>


</body>
</html>